package com.lankystar.logistucs.spring.controller;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lankystar.logistucs.spring.entity.Address;
import com.lankystar.logistucs.spring.entity.Company;
import com.lankystar.logistucs.spring.entity.TruckStatus;
import com.lankystar.logistucs.spring.entity.User;
import com.lankystar.logistucs.spring.entity.UserType;
import com.lankystar.logistucs.spring.service.AddressService;
import com.lankystar.logistucs.spring.service.CompanyService;
import com.lankystar.logistucs.spring.service.TruckStatusService;
import com.lankystar.logistucs.spring.service.UserService;
import com.lankystar.logistucs.spring.service.UserTypeService;

@Controller
@RequestMapping(value="/address")
public class AddressController {
	@Autowired
	private AddressService addressService;
	@Autowired
	private UserService userService;
	@Autowired
	private UserTypeService userTypeService;
	@Autowired
	private CompanyService companyService;
	@Autowired
	private TruckStatusService truckStatusService;
	
	@RequestMapping(value="addAddress.do")
	@ResponseBody
	public Map<String, Object> addAddresslist(){
		////////////////////////////////////////////////
		Map<String, Object> map = new HashMap<>();
		UserType userType1 = userTypeService.queryUserTypeById(4);
		TruckStatus truckStatus = truckStatusService.queryTruckStatusById(5);//司机
		/**
		 * 添加公司
		 */
		Company company1 = companyService.queryCompanyById(3);
		
		User user1 = new User();
		user1.setUserId(1);
		user1.setUserName("苏州报关行");
		user1.setUserPassword("123456");
		user1.setUserPhone("15229360941");
		user1.setUserType(userType1);
		user1.setCompany(company1);
		user1.setUsual(0);
		user1.setRemove(0);
		userService.addUser(user1);
	////////////////////////////////////////////
		UserType userType2 = userTypeService.queryUserTypeById(2);
		/**
		 * 添加公司
		 */
		Company company2 = companyService.queryCompanyById(1);
		
		
		User user2 = new User();
		user2.setUserId(2);
		user2.setUserName("运输队");
		user2.setUserPassword("123456");
		user2.setUserPhone("15229360942");
		user2.setUserType(userType2);
		user2.setCompany(company2);
		user2.setUsual(0);
		user2.setRemove(0);
		userService.addUser(user2);
		//////////////////////////////////////////
		UserType userType3= userTypeService.queryUserTypeById(3);
		/**
		 * 添加公司
		 */
		Company company3= companyService.queryCompanyById(2);
		
		User user3 = new User();
		user3.setUserId(3);
		user3.setUserName("上海报关行");
		user3.setUserPassword("123456");
		user3.setUserPhone("15229360943");
		user3.setUserType(userType3);
		user3.setCompany(company3);
		user3.setUsual(0);
		user3.setRemove(0);
		userService.addUser(user3);
	/////////////////////////////////////////////////////
		/**
		 * 添加司机
		 */
		UserType ut1 = userTypeService.queryUserTypeById(5);
		User u1 = new User();
		u1.setUserId(1);
		u1.setUserName("司机1");
		u1.setUserPassword("123456");
		u1.setUserPhone("15229360944");
		u1.setUserType(ut1);
		u1.setCompany(company2);
		u1.setTruckStatus(truckStatus);
		u1.setUsual(0);
		u1.setRemove(0);
		userService.addUser(u1);
		User u2 = new User();/////////////////////司机2
		u2.setUserId(2);
		u2.setUserName("司机2");
		u2.setUserPassword("123456");
		u2.setUserPhone("15229360945");
		u2.setUserType(ut1);
		u2.setCompany(company2);
		u2.setTruckStatus(truckStatus);
		u2.setUsual(0);
		u2.setRemove(0);
		userService.addUser(u2);
		/**
		 * 添加地址
		 */
			Address address = new Address();
			address.setDetailed("苏州报关行");
			address.setLatitude(0);
			address.setLongitude(0);
			address.setName("张三");
			address.setPhone("15259898647");
			User user = userService.selectUserById(4);
			address.setUser(user);
			addressService.addAddress(address);
			/////////////////////////////////
			Address a = new Address();
			a.setDetailed("苏州xxxx工厂");
			a.setLatitude(0);
			a.setLongitude(0);
			a.setName("张李四");
			a.setPhone("18965324917");
			address.setUser(user);
			addressService.addAddress(a);
			map.put("msg", "添加管理用户、司机、添加地址参数");
		return map;
	}
	
}
